#include "CommandManager.h"


CommandManager::CommandManager() :
   theDirWatcher(this)
{

}

Plugin* CommandManager::getPlugin()
{
   return this;
}

void CommandManager::parseCommandFile(const QFileInfo &file)
{

}

void CommandManager::slotStartService()
{
   theDirWatcher.addPath(DIR_CMDS);
   connect(&theDirWatcher, SIGNAL(directoryChanged(QString)),
           this, SLOT(slotCommandReceived(QString)));
}

void CommandManager::slotStopService()
{

}

void CommandManager::slotConfigUpdate(const QString &key,
                                      QVariant &value)
{

}

void CommandManager::slotEventNotification(Event event)
{

}

void CommandManager::slotCommandReceived(const QString &path)
{
   QDir dir(path);
   QFileInfoList commands = dir.entryInfoList(QStringList() << QString("*" + EXT_CMD));

   foreach(QFileInfo info, commands)
   {
      parseCommandFile(info);
      QFile::remove(info.absoluteFilePath());   // Delete command file
   }
}
